package gameDump;

import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;

/**
 *
 * @author Robin
 */
public class Pacman implements ISprite {

    private Image pacman1, pacman1up, pacman2up, pacman3up;
    private int dx, dy, x, y;
    private final int[][] leveldata = Maze.leveldata2;

    public Pacman() {
        pacman1 = new ImageIcon(this.getClass().getResource("/images/pacman/pacman.png"))
                .getImage();
        pacman1up = new ImageIcon(this.getClass().getResource("/images/pacman/up1.png"))
                .getImage();
        pacman2up = new ImageIcon(this.getClass().getResource("/images/pacman/up2.png"))
                .getImage();
        pacman3up = new ImageIcon(this.getClass().getResource("/images/pacman/up3.png"))
                .getImage();
        x = 0;
        y = 0;



    }

    @Override
    public int getX() {
        return x;
    }

    @Override
    public int getY() {
        return y;
    }

    @Override
    public Image getImage() {
        return pacman1;
    }

    @Override
    public Rectangle getBounds() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void move() {
        int pos;
        int[] posOnScreen;

        if (x % Maze.getBlockSize() == 0 || y % Maze.getBlockSize() == 0) {

            if (y / Maze.getBlockSize() == 0) {
            }

            pos = x / Maze.getBlockSize()
                    + Maze.getNrofblocks() * (int) (y / Maze.getBlockSize());

            posOnScreen = leveldata[pos];


            if ((dx == -24 && dy == 0 && posOnScreen[3] == 1)
                    || (dx == 24 && dy == 0 && posOnScreen[1] == 1)
                    || (dx == 0 && dy == -24 && posOnScreen[0] == 1)
                    || (dx == 0 && dy == 24 && posOnScreen[2] == 1)) {
                System.out.println(pos);
                dx = 0;
                dy = 0;
            }



        }

        x += dx;
        y += dy;



    }

    public void keyPressed(KeyEvent evt) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            dy = 24;
            dx = 0;
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            dy = -24;
            dx = 0;
        }
        if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
            dx = -24;
            dy = 0;
        }
        if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
            dx = 24;
            dy = 0;
        }
    }

    public void keyReleased(KeyEvent evt) {
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            dy = 0;
            dx = 0;
        }
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            dy = 0;
            dx = 0;
        }
        if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
            dx = 0;
            dy = 0;
        }
        if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
            dx = 0;
            dy = 0;
        }
    }
}
